package com.ganlebao.study.springcloudribbonserver;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
@RestController
public class SpringCloudRibbonServerApplication {

    @Value("${spring.application.name}")
    private String applicationName;

    @Value("${timeout.flag}")
    private boolean timeoutFlag;
    public static void main(String[] args) {
        SpringApplication.run(SpringCloudRibbonServerApplication.class, args);
    }


    @GetMapping("echo")
    public String echo(@RequestParam("value") String value) {
        return "你发送的是" + value + ",来自" + applicationName;
    }

    @GetMapping("echo-timeout")
    public String echoWithTimeout(@RequestParam("value") String value) throws InterruptedException {
        if (timeoutFlag) {
            TimeUnit.SECONDS.sleep(5);
        }
        return "你发送的是" + value + ",来自" + applicationName;
    }

}
